package nc.bs.hrhi.bp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import nc.bs.hrhi.op.FileUploadBp;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.pub.BusinessException;

public class BuluFileTypeBp extends AbsPubOp{

	public void exec(String pk_psndoc) throws BusinessException{
		String sql = "select * from sm_pub_filesystem where filepath like '"+pk_psndoc+"%'";
		
		List<Map<String, Object>> list = (List<Map<String, Object>>) getDao().executeQuery(sql, new MapListProcessor());
		
		List<String> need_list = new ArrayList<String>();
		List<String> has_list = new ArrayList<String>();
		List<String> fileTypeList = new FileTypeBp().execAll();
		
		if(list != null && list.size() > 0) {
			String filepath = null;
			String fileType = null;
			for(Map<String, Object> map : list) {
				filepath = (String) map.get("filepath");
				if(filepath.length() == 20) {
					has_list.add(pk_psndoc);
					continue;
				}
				
				filepath = filepath.substring(21, filepath.length());
				fileType = filepath.split("/")[0];
				
				if(fileTypeList.contains(fileType)) {
					has_list.add(fileType);
				}
			}
		}
		
		for(String need : fileTypeList) {
			if(!has_list.contains(need)) {
				need_list.add(pk_psndoc + "/" + need);
			}
		}
		
		if(need_list.size() > 0) {
			FileUploadBp fileUploadBp = new FileUploadBp();
			for(String path : need_list) {
				fileUploadBp.insertIntoFileType(path);
			}
		}
	}
}
